package com.dsj.gxrd.modules.controller.book;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsj.gxrd.modules.book.domain.dto.RdCommShareDto;
import com.dsj.gxrd.modules.book.domain.groups.Group01;
import com.dsj.gxrd.modules.book.domain.groups.Group02;
import com.dsj.gxrd.modules.book.domain.groups.Group03;
import com.dsj.gxrd.modules.book.domain.query.RdCommShareQuery;
import com.dsj.gxrd.modules.book.service.RdCommShareService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author songpin566
 * @date 2023/09/14
 **/
@Api(tags = "书香人大交流分享")
@RestController
@RequestMapping("/comm/share")
public class RdCommShareController extends BaseController {

    private RdCommShareService rdCommShareService;

    public RdCommShareController(RdCommShareService rdCommShareService){
            this.rdCommShareService=rdCommShareService;
    }

    @RequiresPermissions("comm:share:list")
    @GetMapping("/list")
    public AjaxResult list(@Validated RdCommShareQuery share)
    {
        Page<?> list = rdCommShareService.selectRdCommonList(share);
        return AjaxResult.success("查询成功").put("rows",list.getRecords()).put("total",list.getTotal());
    }

    @RequiresPermissions("comm:share:add")
    @Log(title = "【新增交流分享】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated(Group01.class)@RequestBody RdCommShareDto commShareDto)
    {
        return toAjax(rdCommShareService.insertRdCommShare(commShareDto));
    }

    @RequiresPermissions("comm:share:query")
    @GetMapping(value = "/{rdCommShareId}")
    public AjaxResult getInfo(@PathVariable("rdCommShareId") Long rdCommShareId)
    {
        return success(rdCommShareService.selectRdCommShareById(rdCommShareId));
    }

    @RequiresPermissions("comm:share:edit")
    @Log(title = "【修改交流分享】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated(Group02.class)@RequestBody RdCommShareDto commShareDto)
    {
        return toAjax(rdCommShareService.updateRdCommShare(commShareDto));
    }

    @RequiresPermissions("comm:share:remove")
    @Log(title = "【删除交流分享】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{rdCommShareIds}")
    public AjaxResult remove(@PathVariable List<Long> rdCommShareIds)
    {
        return toAjax(rdCommShareService.deleteRdCommShareIds(rdCommShareIds));
    }


}
